{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c174ed27",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "364bd615",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/ssd_failure_tag.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "59ea0c6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "flash_tech = {'A3': 'MLC',\n",
    "                'A6': 'MLC',\n",
    "                'A4': 'MLC',\n",
    "                'A1': 'MLC',\n",
    "                'A5': 'MLC',\n",
    "                'A2': 'MLC',\n",
    "                'B2': 'MLC',\n",
    "                'B3': 'MLC',\n",
    "                'B1': 'MLC',\n",
    "                'C1': '3D-TLC',\n",
    "                'C2': '3D-TLC'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "04798bdf",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['flash_tech'] = df['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "37bbac78",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in flash_tech.items():\n",
    "            df['flash_tech'] = df['flash_tech'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "16ee6b94",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df.groupby('flash_tech')\n",
    "res_df = pd.DataFrame(columns=['flash_tech','failure','all', 'percentage'])\n",
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.loc[row] = [col,group.shape[0], '', '']\n",
    "    \n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "135fbb0e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  flash_tech failure all percentage\n",
      "0     3D-TLC   11641               \n",
      "1        MLC    6746               \n"
     ]
    }
   ],
   "source": [
    "print(res_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f458716a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all = pd.read_csv(\"data/20191231.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c1538fd0",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all['flash_tech'] = df_all['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f1afd362",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in flash_tech.items():\n",
    "            df_all['flash_tech'] = df_all['flash_tech'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1aa7eb24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        disk_id        ds model    n_1           r_1  n_2  r_2  n_3  r_3  n_4  \\\n",
      "0           100  20191231    A6  130.0  4.294967e+09  NaN  NaN  NaN  NaN  NaN   \n",
      "1        100004  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "2        100012  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "3         10003  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "4         10004  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "...         ...       ...   ...    ...           ...  ...  ...  ...  ...  ...   \n",
      "706177     9998  20191231    A2    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "706178    99983  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "706179     9999  20191231    A4    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "706180    99992  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "706181    99999  20191231    B1    NaN           NaN  NaN  NaN  NaN  NaN  NaN   \n",
      "\n",
      "        ...    r_242  n_244  r_244  n_245  r_245  n_175         r_175  n_232  \\\n",
      "0       ...      NaN    NaN    NaN    NaN    NaN  100.0  9.881147e+11    NaN   \n",
      "1       ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "2       ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "3       ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "4       ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "...     ...      ...    ...    ...    ...    ...    ...           ...    ...   \n",
      "706177  ...  58421.0    NaN    NaN    NaN    NaN  100.0  8.935206e+11  100.0   \n",
      "706178  ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "706179  ...  18538.0    NaN    NaN    NaN    NaN  100.0  7.734710e+11  100.0   \n",
      "706180  ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "706181  ...      NaN    NaN    NaN    NaN    NaN    NaN           NaN    NaN   \n",
      "\n",
      "        r_232  flash_tech  \n",
      "0         NaN         MLC  \n",
      "1         NaN         MLC  \n",
      "2         NaN         MLC  \n",
      "3         NaN         MLC  \n",
      "4         NaN         MLC  \n",
      "...       ...         ...  \n",
      "706177    0.0         MLC  \n",
      "706178    NaN         MLC  \n",
      "706179    0.0         MLC  \n",
      "706180    NaN         MLC  \n",
      "706181    NaN         MLC  \n",
      "\n",
      "[706182 rows x 106 columns]\n"
     ]
    }
   ],
   "source": [
    "print(df_all)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "de036141",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df_all.groupby('flash_tech')\n",
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.iloc[row, 2] = group.shape[0]\n",
    "    res_df.iloc[row, 3] = res_df.iloc[row, 1] * 100 / res_df.iloc[row, 2]\n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6539d37d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  flash_tech failure     all percentage\n",
      "0     3D-TLC   11641  187655   6.203405\n",
      "1        MLC    6746  518527   1.300993\n"
     ]
    }
   ],
   "source": [
    "print(res_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a6e989e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='Flash Technology', ylabel='RFR'>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEGCAYAAABvtY4XAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAPq0lEQVR4nO3de4xmdX3H8ffH3VVuirFMDRVxEClWkYtOMQZvxUtBvMZL3bRNMOq2jfUSSy1WjTFGRds0xUuM2/VaV41REIvKJS1osQjOLuu63BQBda0tY1FwVaAs3/7xnC3Pzs7Oszs7Z2b4zfuVPOE5zznn9/1N8vDhx+8553dSVUiS2nO/xe6AJKkfBrwkNcqAl6RGGfCS1CgDXpIatXKxOzDskEMOqfHx8cXuhiTdZ2zYsOFnVTU2074lFfDj4+NMTk4udjck6T4jyQ93t88pGklqlAEvSY0y4CWpUQa8JDXKgJekRhnwktQoA16SGmXAS1KjDHhJatSSupP1vmD8zK8sdheacvNZpy12F6RmOYKXpEYZ8JLUqF4DPsmDk3whyXVJrk3ypD7rSZLu1fcc/NnABVX1kiT3Bw7ouZ4kqdNbwCc5GHgqcDpAVd0F3NVXPUnSzvqcojkCmAI+nuSqJOuSHNhjPUnSkD4DfiXweODDVXUC8CvgzOkHJVmTZDLJ5NTUVI/dkaTlpc+A3wpsraoruu0vMAj8nVTV2qqaqKqJsbEZnzolSZqD3gK+qv4L+HGSo7uPngFc01c9SdLO+r6K5rXA+u4KmhuBV/RcT5LU6TXgq2oTMNFnD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f/TYy3dBxnwWuoO5t5Hvp2+48MkjwRu7Ba0Oo/BgyXm6kLgL7oVOknyu0kOBC5mMEI+oPv8IbO0MZsrgaclOSSDJXFXA1+fdsy/Ay9MckBX+0XdZ98EnpfBc3oPYhDmAHSj+guBD+P0jGZgwGupex/wniRXsfNo+GXAlm7+/hjgU/tQYx1wDbCxu8zyIwzm2C9gsK75ZFfnjLk0XlU/Bc5ksK7/dxiMts+bdsxGBisoXsngCUjrquqqqvp214fNwNeA7wK3DZ26HrgHGPV/HFqGXE1SWuKSHNQ9gP0A4BvAmu4/CCQ5Azi4qt62qJ3UkuSPrNLStzbJYxj8/vDJoXA/FzgSOHm2k7V8OYKXpEY5By9JjTLgJalRBrwkNcqAl6RGGfCS1Kj/A1La6whoLAKwAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "res_df.plot(x = 'flash_tech', y = 'percentage', kind='bar', rot = 0, xlabel = 'Flash Technology', ylabel = 'RFR', legend = None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15638033",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
